package com.wbihua.grpc.demo.spring.mapper;

import lombok.Setter;
import org.springframework.beans.factory.FactoryBean;

@Setter
public class MapperFactoryBean<T>  implements FactoryBean<T> {

    private Class<T> mapperInterface;

    public MapperFactoryBean(Class<T> mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    @SuppressWarnings("unchecked")
    @Override
    public T getObject() throws Exception {
        return (T)new MapperProxy().getInstance(this.mapperInterface);
    }

    @Override
    public Class<?> getObjectType() {
        return this.mapperInterface;
    }

    @Override
    public boolean isSingleton() {
        return FactoryBean.super.isSingleton();
    }
}
